/// <reference path="3rd/jquery.d.ts" />
/// <reference path="3rd/doT.d.ts" />

interface IRenderer {
    render(data: any): string;
}

module Sandbox {
    export class Renderer implements IRenderer {
        private func: Function;

        constructor () { }

        render(data: any): string { 
            var template = doT.template(data.settings.template);
            var func = new Function('var data = {}; var row = arguments[0];' + data.settings.func + ' return data');
            var body = '';

            for (var i = 0; i < data.rows.length; i++) {
                var row = func($(data.rows[i]));
                row.project = data.settings.project;

                body += '<div class="wrap" style="display: inline-block;">';
                body += '<div class="button" style="" onclick="$(this).parent().remove();">Click here to remove</div>';
                body += template(row);
                body += '</div>';
            }
            return body;
        }
    }

}

